package com.mall.pay.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.mall.pay.model.PayLog;
import com.mall.util.RespResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/*****
 * @Author:
 * @Description:
 ****/
@RestController
@RequestMapping(value = "/wx")
@CrossOrigin
public class WeixinPayController {

    @Resource
    private RocketMQTemplate rocketMQTemplate;

    /****
     * 支付结果回调
     */
    @GetMapping(value = "/result")
    public RespResult<PayLog> result(@PathVariable(value = "outno")String outno) throws Exception{
        //PayLog payLog = weixinPayService.result(outno);
        //创建日志对象
        PayLog payLog = new PayLog(IdWorker.getIdStr(), 1, "hello", "AAA", new Date());

        //构建消息
        Message<String> message = MessageBuilder.withPayload(JSON.toJSONString(payLog)).build();
        //发消息
        rocketMQTemplate.sendMessageInTransaction("rocket","log",message,null);

        //Map 响应数据
        Map<String,String> resultResp = new HashMap<String,String>();
        resultResp.put("return_code","SUCCESS");
        resultResp.put("return_msg","OK");
        return RespResult.ok(payLog);
    }



}
